﻿//Editado por Nilton Huamani Carlos
app.controller("profesorController", function ($scope, profesorService) {
    list = function () {
        profesorService.getListByFilter().then(function (r) {
            $scope.profesores = r.data;
        }, function (err) {
            console.log("Errrrr:" + err.data);
        });
    };
    list();
    $scope.save = function () {
        if ($scope.profesor.id) {
            profesorService.update({ id: "" }, $scope.profesor).then(function (r) {
                console.log("ru=" + r.data);
                $scope.profesor = null;
                list();
            }, function (err) {
                console.log("Errrrr:" + err.data);
            });
        } else {
            profesorService.create($scope.profesor).then(function (r) {
                console.log("rc=" + r.data);
                $scope.profesor = null;
                list();
            }, function (err) {
                console.log("Errrrr:" + err.data);
            });
        }
        $scope.formVisibility = false;
        console.log($scope.formVisibility)
    }
    $scope.delete = function (id) {
        profesorService.delete({ "id": id }).then(function (r) {
            console.log("rd=" + r.data);
            list();
        }, function (err) {
            console.log("Errrrr:" + err.data);
        });
    }
    $scope.selec = function (d) {
        $scope.profesor = d;
        $scope.formVisibility = true;
        console.log($scope.formVisibility)
    }
    $scope.formVisibility = false;
    $scope.ShowForm = function () {
        $scope.formVisibility = true;
        console.log($scope.formVisibility)
    }
    $scope.cancel = function () {
        $scope.formVisibility = false;
        console.log($scope.formVisibility)
    }
});